package _07_串;

public class _520_检测大写字母 {

    public static void main(String[] args) {

        _520_检测大写字母 v = new _520_检测大写字母();

        System.out.println(v.detectCapitalUse("ggg"));

    }

    //无论如何，其他字母的大小写一定要和第二个相同
    public boolean detectCapitalUse(String word) {
        int len = word.length();

        if (len >= 2 && Character.isLowerCase(word.charAt(0)) && Character.isUpperCase(word.charAt(1))) return false;

        for (int i = 2; i < len; i++) {
            if (Character.isLowerCase(word.charAt(i - 1)) ^ Character.isLowerCase(word.charAt(i))) return false;
        }

        return true;
    }

    public boolean detectCapitalUse1(String word) {
        // 记录大小写字母出现的位置
        int lowerIndex = -1;
        int upperIndex = -1;
        int len = word.length();
        for (int i = 0; i < len; i++) {
            if (Character.isLowerCase(word.charAt(i))) {
                lowerIndex = i;
            } else {
                upperIndex = i;
            }
        }
        return upperIndex < 1 || lowerIndex < 0;
    }

}
